package principle.singleResponsibility;

/**
 * 例子：运行交通工具
 */
public class SingleResponsibility1 {
    public static void main(String[] args) {
        Vehicle vehicle = new Vehicle();
        vehicle.run("Car");
        vehicle.run("Airplane");
        vehicle.run("Ship");
    }
}


class Vehicle {
    /* ****************************************
     * 方案一：
     * 违反了单一职责原则
     * 不同的交通工具的运行场景景不同，全部都由Vehicle负责
     *
     * 想这种负责多个职责的最好是作为抽象，而不是一种类！
     * ***************************************/
    public void run(String name) {
        if (name.equals("Car"))
            System.out.println(name + " run on the road");
        else if (name.equals("Airplane"))
            System.out.println(name + " fly in the air");
        else if (name.equals("Ship"))
            System.out.println(name + " run on the water");
    }

   /* *******************************
    * 方法级别的单一职责
    * ******************************/

   public void runAir(String name) {
       System.out.println(name + " run in the air");
   }

   public void runWater(String name) {
       System.out.println(name + " run on the water");
   }

   public void runRoad(String name) {
       System.out.println(name + " run on the road");
   }
}
